import 'package:flutter/material.dart';

/// 评分控件
class RatingBar extends StatefulWidget {
  // 个数
  final int count;

  // 最大值
  final double maxRating;

  // 评分数值
  final double value;

  // 间隔
  final double padding;

  // 默认图
  final String normalImage;

  // 选中图
  final String selectImage;

  final bool selectAble;

  // 大小
  final double size;

  // 当数值发生改变监听
  final ValueChanged<String> onRatingUpdate;

  RatingBar(this.normalImage, this.selectImage, this.padding,
      {this.count = 5,
      this.maxRating = 10.0,
      this.value = 10.0,
      this.size = 20,
      this.selectAble = false,
      required this.onRatingUpdate});

  @override
  _RatingBarState createState() => _RatingBarState();
}

class _RatingBarState extends State<RatingBar> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }

  // 构建默认评分
  List<Widget> buildNormalRow() {
    List<Widget> children = [];
    for (int i = 0; i < widget.count; i++) {
      children.add(Image.asset(
        widget.normalImage,
        width: widget.size,
        height: widget.size,
      ));
      // 添加间隔
      if (i < widget.count - 1) {
        children.add(SizedBox(
          width: widget.padding,
        ));
      }
    }
    return children;
  }
}
